@echo off
REM 快速启动脚本（Windows）- 启动所有服务
echo ========================================
echo 快速启动所有服务
echo ========================================
echo.

REM 检查Redis
echo 检查Redis连接...
python -c "import redis; r = redis.Redis(host='127.0.0.1', port=6379, db=0); r.ping(); print('Redis连接正常')" 2>nul
if errorlevel 1 (
    echo 警告: Redis未运行，Celery将无法启动
    echo 请先启动Redis: redis-server
    echo.
)

REM 启动后端服务
echo 启动Django后端服务...
start "Django Server" cmd /k "cd /d %~dp0.. && venv\Scripts\activate.bat && python manage.py runserver"
timeout /t 3 /nobreak >nul

REM 启动Celery Worker
echo 启动Celery Worker...
start "Celery Worker" cmd /k "cd /d %~dp0.. && venv\Scripts\activate.bat && celery -A travel_plan worker --loglevel=info --pool=solo"
timeout /t 2 /nobreak >nul

REM 启动Celery Beat
echo 启动Celery Beat...
start "Celery Beat" cmd /k "cd /d %~dp0.. && venv\Scripts\activate.bat && celery -A travel_plan beat --loglevel=info"
timeout /t 2 /nobreak >nul

REM 启动前端服务
cd ..\frontend
if exist package.json (
    echo 启动前端服务...
    start "Vue Frontend" cmd /k "cd /d %~dp0..\frontend && npm run serve"
) else (
    echo 警告: 前端目录不存在或package.json未找到
)
cd ..\backend

echo.
echo ========================================
echo 所有服务已启动！
echo ========================================
echo.
echo 服务窗口已打开：
echo - Django Server (后端API)
echo - Celery Worker (异步任务)
echo - Celery Beat (定时任务)
echo - Vue Frontend (前端界面)
echo.
echo 访问地址：
echo - 前端: http://localhost:8080
echo - 后端API: http://localhost:8000/api/
echo.
echo 按任意键关闭此窗口（服务将继续运行）...
pause >nul

